
/* Initial beliefs and rules */
/* BELIEFS */


/* RULES */



/* initial DESIRES */
!search_switch.


/* INTENTIONS (PLANS AND ACTIONS) */
+!find_pos : true
	<- .wait("+pos(_,_,_)").
	
+!search_switch : not pos(_,_,_)
	<-	!find_pos;
		!search_switch.
	
+!search_switch : pos(_,_,_)  & switch(_,SX,SY)
  	<- 	+target(SX,SY);
  	 	!move.

+!search_switch : pos(_,_,_)  & not switch(_,_,_)
  	<- 	!move.

	
+!search_switch : pos(X,Y,_) & fence(_,_,S)
	<-	.print("Procurando switch!");
		if(S == closed){
			.print("fence fechado");	
		}else{
			.print("fence aberto");
		}
		!search_switch.

+!move : pos(X,Y,_) & not switch(_,_,_)
  <- .print("move random");
     br.poli.ecomp.sma.massim.action.RandomPos(X,Y,NewX,NewY);
     br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     moveTo(Direction);
     .wait("+pos(_,_,_)");
     !search_switch.

+!move : pos(X,Y,_) & target(Cx,Cy) & Cx \== X & Cy \== Y
  <- .print("move to target");
  	 br.poli.ecomp.sma.massim.action.FindPos(X,Y,Cx,Cy,NewX,NewY);
     br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     moveTo(Direction);
     !move.

+!move : pos(X,Y,_) & target(Cx,Cy) & (Cx == X-1 | Cx == X+1) & (Cy == Y-1 | Cy == X+1)
  <- .print("Switch encontrado");
     -target(Cx,Cy).
	